#include "MainHeader.h"


int GetTileset(u8 Tileset){
	//INSERTCALLTOENGINE
	GameEngine->GetTileset(Combos[cRoom].GetListIndex(),Tileset);
	TileImage.Load(GameEngine->Members.fGbuf,1024);
 
    DrawTileset();


     BGImage.Load(GameEngine->Members.BGBuf,1024);



	return 0;

}
int DrawBlock(short Map16n , int destX , int destY){
 
	    img[0].Draw(TileImage,(destX), (destY), (short)GameEngine->Members.TSA.nTSA[Map16n]);
		img[0].Draw(TileImage,(destX) + 8, (destY), (short)GameEngine->Members.TSA.nTSA[(Map16n)+1]);
		img[0].Draw(TileImage,(destX), (destY) + 8, (short)GameEngine->Members.TSA.nTSA[Map16n+2]);
		img[0].Draw(TileImage,(destX) + 8, (destY) + 8, (short)GameEngine->Members.TSA.nTSA[Map16n+3]);
	
		return 0;
}
void DrawTileset(){
    int k=0;
    int i=0;
	int TC=0;
	int end=768;
	
 
  
	img[0].Clear();
	img[0].SetPalette(GameEngine->Members.PcPalMem);
//	BBTileset.Create(512,512);
    
	for( i= 0; i<GameEngine->Members.TSA.max;i++)
	{
      
		     DrawBlock( i*4, (i % 16) * 16, ((i / 16)) * 16);


    }
//    img[0].Blit(BBTileset.DC(),0,0,512,512,0,0);
	nVScroll[sTileset] = 0;
    InvalidateRect(hwndTileset,0,1);

}


int ZMGlobalGFX(u8 Area){
/*
Dim g2Buf(0 To 4096) As Byte
Dim thispal(0 To 15) As Integer
Dim fakepal(1 To 15) As Integer
Dim thatpal(0 To 0, 0 To 15) As Long*/


if( Area == 6){
   
   fseek(GBA.ROM,0x5DA40C,SEEK_SET);
   fread(&GameEngine->Members.fGbuf[2048],1,4098,GBA.ROM);
    //If (header = "PBMXP01") Then Get GBA.ROM, &H5ED460 + 1, g2Buf
   
}else{
  
   fseek(GBA.ROM,0x5D940C,SEEK_SET);
   fread(&GameEngine->Members.fGbuf[0x800],1,4098,GBA.ROM);
//    If (header = "PBMXP01") Then Get GBA.ROM, &H5EC460 + 1, g2Buf
}
	
//Get FileNo, &H3ED51C, thispal
//Get FileNo, &H31C72E, fakepal
//If (header = "PBMXP01") Then Get FileNo, &H3EE1A9, thispal
//If (header = "PBMXP01") Then Get FileNo, &H31D3BB, fakepal
//'CopyMemory GbaPalMem(1), fakepal(1), 15
/*
For i = 1 To 15
GbaPalMem(i) = fakepal(i)
GbaPalMem(i + 16) = thispal(i)
Next i*/



//CopyMemory fGbuf(2048), g2Buf(0), 4096

return 0;
}


int MFGlobalGFX(){




GBA.GBAPal[0] = 0;
fseek(GBA.ROM,0x40805E,SEEK_SET);
fread(&GBA.GBAPal[1],2,47,GBA.ROM);

fseek(GBA.ROM,0x3F28C8,SEEK_SET);
fread(&GameEngine->Members.fGbuf[0x800],1,4098,GBA.ROM);

return 0;

}




